package com.gm.corejava.book2;

import javax.swing.*;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
import javax.swing.table.TableModel;
import java.awt.*;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 13-12-26
 * Time: 上午10:18
 * To change this template use File | Settings | File Templates.
 */
public class TableRenderFrame extends JFrame {
    public TableRenderFrame() throws HeadlessException {
        setTitle("Table Render ");
        setSize(DEFALT_WIDTH,DEFAULT_HEIGHT);

        TableModel tableModel=new PanetTableModel();
        JTable table=new JTable(tableModel);
        table.setRowSelectionAllowed(false);

        //Color Editor and Render
        table.setDefaultRenderer(Color.class,new ColorTableRenderer());
        table.setDefaultEditor(Color.class,new ColorTableCellEditor());

        JComboBox<Integer> moonComboBox=new JComboBox<Integer>();

        for(int i=0;i<20;i++)
            moonComboBox.addItem(i);

        TableColumnModel tableColumnModel=table.getColumnModel();
        TableColumn moonColumn=tableColumnModel.getColumn(PanetTableModel.MOON_COLUMN);
        moonColumn.setCellEditor(new DefaultCellEditor(moonComboBox));

        add(new JScrollPane(table), BorderLayout.CENTER);
    }


    private final int DEFALT_WIDTH=400;
    private final int DEFAULT_HEIGHT=400;
}
